package cn.bs.seckill.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.Topic;

@Configuration
public class RabbitMQTopicConfig {


    private static final String QUEUE_5 = "我是主题队列一的消息";
    private static final String QUEUE_6 = "我是主题队列二的消息";
    private static final String EXCHANGE = "我是主题模式的交换机";
    private static final String ROUTING_KEY1 = "*.cgb2109";
    private static final String ROUTING_KEY2 = "cgb2111.#";

    //新建队列一
    @Bean
    public Queue queue5() {
        return new Queue(QUEUE_5);
    }

    //新建队列二
    @Bean
    public Queue queue6() {
        return new Queue(QUEUE_6);
    }

    //新建主题模式交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE);
    }

    //把队列和交换机以及路由键绑定
    @Bean
    public Binding binding5() {
        return BindingBuilder.bind(queue5()).to(topicExchange()).with(ROUTING_KEY1);
    }

    @Bean
    public Binding binding6() {
        return BindingBuilder.bind(queue6()).to(topicExchange()).with(ROUTING_KEY2);
    }

}


